package com.wechat.core;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wechat.model.wechat.Button;
import com.wechat.model.wechat.ComplexButton;
import com.wechat.model.wechat.Menu;
import com.wechat.model.wechat.ViewButton;
import com.wechat.utils.TokenThread;
import com.wechat.utils.WechatMessageUtils;

@Controller
@RequestMapping(value = "createMenuController")
public class CreateMenuController {
	// 创建菜单链接
	public static final String USERURL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=";
	// 请求方式
	public static final String METHOD = "GET";
	// 提交的数据
	public static final String STR = "";
	// 服务器
	public static final String SERVER_NAME = "127.0.0.1";
	// http://localhost:80/CAA/createMenuController/execute
	@RequestMapping(value = "/execute")
	public String execute() {
		// 修=修改创建菜单后 访问下面的网页
		// http://caa.e2bao.cn/CAA/createMenuController/execute
		// 创建菜单
		WechatMessageUtils.createMenu(getMenu(), TokenThread.accessToken.getToken());
		return "";
	}
	/**
	 * 生成服务号的菜单 APPID 为服务号appid APPSECRET 为服务号的秘钥
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(getMenu());
		WechatMessageUtils.createMenu(getMenu(), "-Kyx1rekop-DpqOuenYF7o1uqw2LRORIw7vIyGqIyga8G1EVFeecMQnTKjpfMuEy9N8EnjFlayAisyj40EwWF-HiSfwvtPlkaHdLujH7C5SObhhOS_P8xEwjYQ2WuBMFNMVgAJAZYH");
	}
	// 生成微信菜单Action
	private static Menu getMenu() {

		ViewButton btn11 = new ViewButton();
		btn11.setName("首页");
		btn11.setType("view");
		btn11.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WechatMessageUtils.APPID + "&redirect_uri=http%3a%2f%2f" + SERVER_NAME + "%2fname%2fgloble%2flogin.shtml&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect");

		ViewButton btn22 = new ViewButton();
		btn22.setName("分类");
		btn22.setType("view");
		btn22.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WechatMessageUtils.APPID + "&redirect_uri=http%3a%2f%2f" + SERVER_NAME + "%2fname%2fgloble%2flogin.shtml&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect");

		ViewButton btn33 = new ViewButton();
		btn33.setName("关于");
		btn33.setType("view");
		btn33.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WechatMessageUtils.APPID + "&redirect_uri=http%3a%2f%2f" + SERVER_NAME + "%2fname%2fgloble%2flogin.shtml&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect");

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("菜单1");
		mainBtn3.setSub_button(new Button[] { btn33 });
		Menu menu = new Menu();
		menu.setButton(new Button[] { btn11, btn22, btn33 });

		return menu;
	}
}